
.<div class="bjui-pageContent">
    <form id="product-edit" class="form-horizontal" method="post"  action='/product/edit'>
        <input type="hidden"  class="form-control input-nm" name="id" id="product-id" value="{{id}}" >
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>产品名称:
                
            </label>
            <div class="col-lg-12 col-sm-12">
                <input type="text" class="form-control input-nm" id="product-name" name="name">
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>产品编号:
                
            </label>
            <div class="col-lg-12 col-sm-12">
                <input type="text" class="form-control input-nm" id="product-pno" name="pno">
            </div>
        </div>
        <div class="form-group ">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>通信协议:
                 
            </label>
            <div class="col-lg-12 col-sm-12">
                <select class="selectpicker show-tick form-control"  name="communicationprotocolid" id="product-communicationprotocolid" style="height: 36px;">
                    <option value="" disabled selected  style = 'display：none;' >请选择通信协议</option>
                </select>

            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label">产品描述:
            </label>
            <div class="col-lg-12 col-sm-12">
                 <textarea style="width: 100%;height: 100px;" name="memo" id="product-memo"></textarea>
            </div>
        </div>
       
    </form>
</div>
<div class="btns-group bjui-pageFooter">
    <button type="button" class="close-btn">取消</button>
    <button type="submit" class="save-btn">保存</button>
</div>
<script type="text/javascript">

    $(document).ready(function() {
        get_communicationProtocol_list();
        $('.selectpicker').selectpicker();
          dialog_close(); 
          
        $('#product-edit').find('[name="communicationprotocolid"]') .selectpicker() .change(function(e) { /* Revalidate the language when it is changed */ 
            $('#product-edit').formValidation('revalidateField', 'communicationprotocolid'); 
        }) .end().formValidation({            //表单
            // message: 'This value is not valid',
            framework: 'bootstrap', 
            excluded: ':disabled',
            trigger:'blur', 
            icon: { valid: 'glyphicon glyphicon-ok', 
            invalid: 'glyphicon glyphicon-remove', 
            validating: 'glyphicon glyphicon-refresh' }, 
            fields: {                                 
                name: {                       
                    validators: {                
                        notEmpty: {
                            message: '请填写产品名称'
                        },
                        regexp: {
                            regexp: /^[\u4e00-\u9fa5_a-zA-Z0-9-]{2,30}$/,
                            message: '产品名称只能由字母、数字、中文、下划线和减号组成,长度必须2到30之间'
                        }
                    }
                },
                pno: {
                    validators: {
                        notEmpty: {
                            message: '请填写产品编号'
                        },
                        regexp:{
                            regexp: /^[a-zA-Z0-9]{2,30}$/,
                            message:'产品编号只能由字母、数字组成,长度必须2到30之间'
                        }
                    }
                },
                communicationprotocolid: {
                    validators: {
                        notEmpty: {
                            message: '请选择通信协议'
                        }
                    }
                },
                memo:{
                    validators: {
                        stringLength:{
                          message:'产品描述不得超过200个字符',
                          max:200
                        }
                    }
                }            
            }
        })
        .on('success.form.fv', function(e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the FormValidation instance
            var bv = $form.data('formValidation');
            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
                if(result.statusCode=='200'){
                    BJUI.alertmsg('ok',result.message);
                    BJUI.dialog('closeCurrent');
                    BJUI.navtab('refresh', 'product');
                    // BJUI.navtab('refresh', 'sysprotocol')
                }else{
                    BJUI.alertmsg('error',result.message);
                }
            }, 'json');
        });



    });

    function get_Product(id){
        $.ajax({
        url:'/product/getProduct',
        type:'post',
        data:{'id':id},
        dataType:'json',
        success:function(json){
           $("#product-name").val(json.data.name);
           $("#product-memo").val(json.data.memo);
           $('#product-pno').val(json.data.pno); 
           $('#product-communicationprotocolid').val(json.data.communicationprotocolid);
           $('#product-communicationprotocolid').selectpicker('render');

        }
    })
    }
    function get_communicationProtocol_list(){
        $.ajax({
            url:"/product/getcommunicationprotocollist",
            type:"post",
            dataType:"json",
            success:function(data){
                var productid=$("#product-id").val();
                if(data.statusCode=='200'){
                    $.each(data.list,function(i,item){
                        $("#product-communicationprotocolid").append('<option value="'+item.id+'" >'+item.protocol+'</option>')
                    })
                }
                $("#product-communicationprotocolid").selectpicker('render');
                $("#product-communicationprotocolid").selectpicker('refresh');
                if(productid){
                    get_Product(productid);
                }
            }
        })
    }
</script>